package com.gjm.order.service.impl;

import com.gjm.order.dao.objectdata.OrderInfo;
import com.gjm.order.dao.mapper.OrderMapper;
import com.gjm.order.service.OrderService;
import com.gjm.product.api.ProductServiceApi;
import com.gjm.product.model.ProductInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Resource(name = "orderMapper")
    private OrderMapper orderMapper;

    @Resource(name = "restTemplate")
    private RestTemplate restTemplate;

    @Autowired
    private ProductServiceApi productServiceApi;

    @Override
    public OrderInfo getOrderInfoById(Integer orderId) {
        OrderInfo orderInfo = orderMapper.getOrderInfoById(orderId);

        Integer productId = orderInfo.getProductId();
        log.info("productId: {}", productId);

        ProductInfo productInfo = productServiceApi.getProductInfoById(productId);

        orderInfo.setProductInfo(productInfo);

        return orderInfo;
    }

//    @Override
//    public OrderInfo getOrderInfoById(Integer orderId) {
//        OrderInfo orderInfo = orderMapper.getOrderInfoById(orderId);
//
//        String url = "http://product-service/product/getProductInfoById?productId=" + orderInfo.getProductId();
//
//        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);
//
//        orderInfo.setProductInfo(productInfo);
//
//        return orderInfo;
//    }
}
